﻿using BLL;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

using Common;


namespace PropertyAppraisal
{
    public partial class LiXiangList : System.Web.UI.Page
    {
        //部门表
        private static DepartmentBll Depbll = new DepartmentBll();
        //借款人表
        private static Loan_InfoBll Loanbll = new Loan_InfoBll();
        //项目信息表
        private static Basic_InfoBll Basicbll = new Basic_InfoBll();
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request["id"];
            if (id != null)
            {
                daochu(id);
            }
            

        }

        /// <summary>
        /// 显示登记列表
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public static string showDeng()
        {

            var result = Basicbll.DList();
            //linq联查
            //var result = from b in Basicbll.Show().ToList()
            //             join d in Depbll.Show().ToList() on b.the_Department equals d.department_Id
            //             join l in Loanbll.Show().ToList() on b.projectNumber equals l.projectNumber
            //             select new
            //             {
            //                 a = b.projectNumber,
            //                 b = d.department_Name,                                                                                                                                       
            //                 c = l.loan_Name,
            //                 d = l.loan_TEL,
            //                 e = b.basic_Quota,
            //                 f = b.basic_CreateTime,
            //                 g = b.basic_State
            //             };
            //select Tuple.Create(
            //       b.projectNumber,
            //       d.department_Name,
            //       l.loan_Name,
            //       l.loan_TEL,                                            
            //       b.basic_Quota,
            //       b.basic_CreateTime,
            //       b.basic_State     
            //);
            return JsonConvert.SerializeObject(result);
        }

        /// <summary>
        ///导出
        /// </summary>
        /// <returns></returns>
        public void daochu(string id)
        {
            var result = Basicbll.Back(id).FirstOrDefault();



            //模板地址
            string TemplateName = Server.MapPath("\\files\\五组地产评估模板.doc");

            //保存地址
            string SaveName = Server.MapPath(string.Format("\\files\\五组地产评估模板{0}.doc", DateTime.Now.ToString("yyyyMMdd")));
           
            //模板内容
            List<WordsTemp> lwt = new List<WordsTemp>();
            lwt.Add(new WordsTemp() { Name = "借款人", Value = result.Loan_Name });
            lwt.Add(new WordsTemp() { Name = "借款人身份证号", Value = result.Loan_IdCard });
            lwt.Add(new WordsTemp() { Name = "部门", Value = result.Department_Name });


            lwt.Add(new WordsTemp() { Name = "编号", Value = result.ProjectNumber });
            lwt.Add(new WordsTemp() { Name = "出具年", Value = result.Issue_Time.Year.ToString() });
            lwt.Add(new WordsTemp() { Name = "出具月", Value = result.Issue_Time.Month.ToString() });
            lwt.Add(new WordsTemp() { Name = "出具日", Value = result.Issue_Time.Day.ToString() });
            lwt.Add(new WordsTemp() { Name = "登记年", Value = result.Basic_CreateTime.Year.ToString() });
            lwt.Add(new WordsTemp() { Name = "登记月", Value = result.Basic_CreateTime.Month.ToString() });
            lwt.Add(new WordsTemp() { Name = "登记日", Value = result.Basic_CreateTime.Day.ToString() });
            lwt.Add(new WordsTemp() { Name = "建筑面积", Value = result.Basic_Acreage.ToString() });
            lwt.Add(new WordsTemp() { Name = "剩余年", Value = result.Surplus_Years.ToString() });
            lwt.Add(new WordsTemp() { Name = "最高贷款额", Value = result.Basic_Quota.ToString() });


            lwt.Add(new WordsTemp() { Name = "地址", Value = result.Floor_Address.ToString() });
            lwt.Add(new WordsTemp() { Name = "用途", Value = result.Dictionary_Name.ToString() });
            lwt.Add(new WordsTemp() { Name = "当天年", Value = DateTime.Now.Year.ToString() });
            lwt.Add(new WordsTemp() { Name = "当天月", Value = DateTime.Now.Month.ToString() });
            lwt.Add(new WordsTemp() { Name = "当天日", Value = DateTime.Now.Day.ToString() });

            CommonWords.Word(TemplateName, SaveName, lwt);
        }

        /// <summary>
        /// 本地路径转换成URL相对路径
        /// </summary>
        /// <param name="imagesurl1"></param>
        /// <returns></returns>
        private string urlconvertor(string imagesurl1)
        {
            string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录
            string imagesurl2 = imagesurl1.Replace(tmpRootDir, ""); //转换成相对路径
            imagesurl2 = imagesurl2.Replace(@"\", @"/");
            //imagesurl2 = imagesurl2.Replace(@"Aspx_Uc/", @"");
            return "/" + imagesurl2;
        }

    }
}